#include <stdlib.h>
#include "common_func.h"
#include "i2c.h"
#include "gpio.h"
#include "i2c_AT24CXX.h"

#define RAM_SIZE  128

int  simu_flag;

int main(int argc, char** argv)
{   
    uint32_t i;
    uint8_t ram[RAM_SIZE];
	uint8_t read_ram[RAM_SIZE];

	simu_flag = RegRead(0xbf20f500);

	printf("I2C TEST BEGIN\n");

    //Prepare Ram Data 0-255 0-255 ...
	for(i = 0; i<RAM_SIZE; i=i+1){
		ram[i] = i;
	}

    // Init I2C
    AT24CXX_Init();

    // Write EEPROM
	AT24CXX_Write(0x0000,ram,RAM_SIZE);

    // Read EEPROM
	AT24CXX_Read(0x0000,read_ram,RAM_SIZE);

    //Check EEPROM Read Date
    for(i = 0; i<RAM_SIZE; i=i+1){
		if(read_ram[i] != ram[i]){
			printf("Error : read_ram[%d] = %d, ram[%d] = %d\n",i,read_ram[i],i,ram[i]);
			break;
		}
	}
	printf("I2C TEST PASS!!\n");
	printf("read_ram[0]=%d\n",read_ram[0]);
	printf("read_ram[1]=%d\n",read_ram[1]);
	printf("read_ram[%d]=%d\n",RAM_SIZE-2,read_ram[RAM_SIZE-2]);
	printf("read_ram[%d]=%d\n",RAM_SIZE-1,read_ram[RAM_SIZE-1]);

	return 0;
}
